import { UiButton } from "@/shared/Uikit";
import { UiSelectField } from "@/shared/Uikit/UiSelectField";
import { UiTextField } from "@/shared/Uikit/UiTextField";
import { useSetRole } from "../model/useSetRole";
import { useGetCurrentUser } from "@/entities/user/model/useGetCurrentUser";


export default function UiSetRole() {
    const { register, handleSubmit, errorMessage } = useSetRole()
    const { user } = useGetCurrentUser();
    if (user?.role != 'ADMIN') return null
    return (
        <div className='flex flex-col gap-4'>
            <h1 className='font-bold text-lg'>Управление ролями:</h1>
            <form className="flex flex-col gap-2" onSubmit={handleSubmit}>
                <UiTextField
                    label="Электронная почта"
                    inputProps={{
                        type: "email",
                        placeholder: "Email",
                        ...register("email", { required: true })
                    }}
                />
                <UiSelectField
                    label="Роль"
                    selectProps={
                        {
                            ...register("role", { required: true })
                        }
                    }
                    options={[
                        { label: "Администратор", value: "ADMIN" },
                        { label: "Пользователь", value: "USER" },
                        { label: "Ученик", value: "STUDENT" },
                        { label: "Преподаватель", value: "TEACHER" },
                    ]
                    }

                />
                <UiButton variant="primary">
                    Установить роль
                </UiButton>
                {errorMessage && <div className="text-rose-500">{errorMessage}</div>}
            </form>
        </div>
    )
}